import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:get/get.dart';
import 'package:nft_shop/my/model/models.dart';
import 'package:nft_shop/net/dio_api.dart';
import 'package:nft_shop/net/service_repository.dart';
import 'package:nft_shop/res/global.dart';
import 'package:nft_shop/widgets/my_app_bar.dart';
import 'package:nft_shop/widgets/my_button.dart';
import 'package:nft_shop/widgets/my_scroll_view.dart';
import 'package:nft_shop/widgets/my_text_field.dart';

class PaymentAccountPage extends StatefulWidget {
  const PaymentAccountPage({Key? key}) : super(key: key);

  @override
  _PaymentAccountPageState createState() => _PaymentAccountPageState();
}

class _PaymentAccountPageState extends State<PaymentAccountPage> {
  final TextEditingController _Controller1 = TextEditingController();
  final TextEditingController _Controller2 = TextEditingController();

  final FocusNode _nodeText1 = FocusNode();
  final FocusNode _nodeText2 = FocusNode();

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    getmemberExtend();
  }
  void getmemberExtend() async{
    try {
      EasyLoading.show(status: "加载中");
      MemberExtendModel model = await ServiceRepository.memberExtend();
      EasyLoading.dismiss();
      _Controller1.text = model.alipayName??"";
      _Controller2.text = model.alipayAccount??"";
    } catch (e, s) {
    }
  }


  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: MyAppBar(
        centerTitle: "收款账号",
      ),
      body: MyScrollView(
        padding: EdgeInsets.symmetric(horizontal: 15,),
        children: [
          Container(
            height: 53,
            child: Align(alignment: Alignment.centerLeft, child: Text("请填写您的支付宝信息",style: TextStyle(fontSize: 16,color: Color(0xFF131415),fontFamily: "PingFangSC-Semibold",),)),
          ),
          SizedBox(height: 12),
          Text(
            "支付宝姓名",
            style: TextStyle(
                fontSize: 14,
                fontFamily: "PingFangSC-Semibold",
                color: Global.kTheme.textPrimary6),
          ),
          MyTextField(
            keyName: 'name',
            maxLength: 40,
            focusNode: _nodeText1,
            controller: _Controller1,
            hintText:"请输入支付宝姓名",
          ),
          SizedBox(height: 16),
          Text(
            "支付宝账号",
            style: TextStyle(
                fontSize: 14,
                fontFamily: "PingFangSC-Semibold",
                color: Global.kTheme.textPrimary6),
          ),
          MyTextField(
            keyName: 'card',
            maxLength: 40,
            focusNode: _nodeText2,
            controller: _Controller2,
            hintText:"请输入支付宝账号",
          ),
          SizedBox(height: 30),
          Container(
            height: 40,
            decoration: BoxDecoration(
              color: Global.kTheme.colorBackground3,
              borderRadius: BorderRadius.circular(4),
            ),
            child: MyButton(
              minHeight: 40,
              onPressed: () async {

                if (_Controller1.text.length == 0) {
                  EasyLoading.showToast('请输入支付宝姓名');
                  return;
                }
                if (_Controller2.text.length == 0) {
                  EasyLoading.showToast('请输入支付宝账号');
                  return;
                }
                EasyLoading.show(status: "加载中");
                try {
                  await ServiceRepository.paymentCertification(_Controller1.text,_Controller2.text);
                  EasyLoading.showToast("上传成功");
                  Get.back();
                } catch (e, s) {
                  EasyLoading.showToast(http.setError(e,s));
                }
              },
              text: "提交",
              fontSize: 16,
              textColor: Colors.white,
              backgroundColor: Global.kTheme.colorBackground3,
            ),
          ),
        ],
      ),
    );
  }
}
